/**
 * 
 */
package org.lora.smp.common;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.lora.biz.ou.entity.EmployeeIdentityView;
import org.lora.biz.ou.exception.LoraOrgUserException;
import org.lora.biz.ou.service.IEmployeeIdentityService;
import org.lora.biz.workflow.WorkflowConstant;
import org.lora.biz.workflow.engines.ExcuterBean;
import org.lora.core.annotation.Action;
import org.lora.core.annotation.AutoAssemble;
import org.lora.mvc.annotation.RequestPath;
import org.lora.smp.document.DocumentContentEntity;
import org.lora.util.ValidateUtil;
import org.lora.webframework.common.WebframeBaseAction;

/**
 * <p>
 * 类名:SmpCommconAction
 * </p>
 * 描述:短信统筹公共Action<br>
 * 创建时间:2016年10月24日 下午4:23:08<br>
 * 
 * @author Bladnir@outlook.com<br>
 *         修改历史:<br>
 *         2016年10月24日 Bladnir 创建<br>
 */

@Action
@RequestPath(path = "/smp/common")
public class CommconSmpAction extends WebframeBaseAction {

	@AutoAssemble
	private IEmployeeIdentityService employeeIdentityService;

	protected ExcuterBean getCurrentExcuterBean() {

		ExcuterBean excuterBean = new ExcuterBean();

		excuterBean.setExecuteName("孙咏霞");
		excuterBean.setExecuteAccountId("EMP-07X74TUV-ATAF-21BN-I4LB-NLODAZ3KQ3SH");
		excuterBean.setExecuteId("EI-92FAAC30-75DC-4A17-9A63-BAD9609FAC74");
		excuterBean.setExecuteType(WorkflowConstant.EXCUTER_TYPE_EI);

		return excuterBean;

	}

	protected DocumentContentEntity getDocumentContentFromRequest(HttpServletRequest request) {

		String teamLeaderId = request.getParameter("teamLeaderId");
		String opinion = request.getParameter("opinion");
		String domainId = request.getParameter("domainId");

		DocumentContentEntity entity = new DocumentContentEntity();

		entity.setDomainId(domainId);
		entity.setOpinion(opinion);
		entity.setTeamLeaderId(teamLeaderId);
		return entity;
	}

	protected ExcuterBean getExcuterBeanByEiId(String eiId, String domainId) throws LoraOrgUserException {
		Map<String, Object> parameterMap = new HashMap<>();

		parameterMap.put("eiId", eiId);

		List<EmployeeIdentityView> list = employeeIdentityService.getEmployeeIdentityDetailList(domainId, parameterMap, null, null);
		if (ValidateUtil.isEmpty(list)) {
			return null;
		}

		EmployeeIdentityView eiBean = list.get(0);

		ExcuterBean excuterBean = new ExcuterBean();

		excuterBean.setExecuteName(eiBean.getEmpName());
		excuterBean.setExecuteAccountId(eiBean.getEmpId());
		excuterBean.setExecuteId(eiBean.getEiId());
		excuterBean.setExecuteType(WorkflowConstant.EXCUTER_TYPE_EI);

		return excuterBean;

	}

}
